$(document).ready(function() {
	WeekDayCanvas();
	WeekNightCanvas();
	WeekEveryDayCanvas();
	GetAge();
	weekDayAvg();
	if($("#sex").html()=="M"){
    	$("#sex").html("男")
    }else{
    	$("#sex").html("女")
    };
    //日历选择器
    laydate.render({
		elem: '#canvas-dayhour-time', //指定元素
	 	done: function(date){
	 		$('.canvas-title').css({'display':'none'});
	 		$('#canvas-dayhour').css({'display':'block'});
	 		var time = new Date(date);
	 		var timeStr= time.getTime();
	 		var url= '/data/getBpByTime';
	$.ajax({
		url : url,
		type : 'POST',
		data : {
			"patientId" : $("#patientId").val(),
			"time":timeStr
		},
		success : function(data) {
			var result =data.list;
			var dayTime=[];
			 var xueya=[];
			if(result.length !=0){
				for(var i=0;i<result.length;i++){
					dayTime.push(timestampToHour(result[i].time))
					xueya.push([result[i].sbp,result[i].dbp])
				}
				DayHourCanvasByDay(dayTime,xueya,result)
			}else {
				DayHourCanvas()
			}
			
		},
		error : function(jqXHR, textStatus, errorThrown) {
			console.log(errorThrown);
		},
		dataType : "json",
		async : true
	});
	 	
	 	}
	});
});
function weekDayAvg(){
	
	  var dayTime=[];
	    $("input[name='dayTime1']").each(function(index,a){
	    	dayTime.push(timestampToTime($(this).val()))
			});
	    
	    var dNight=[];
	    var sNight=[];
		  $("input[name='diastolicNightAvg1']").each(function(index,a){
			  dNight.push($(this).val())
			});
		
		  $("input[name='systolicNightAvg1']").each(function(index,a){
			  sNight.push($(this).val())		  
			});
		var indexNight=0;
	    var strnight='';
	    var nightsbp='';
	    var nightdbp='';
	    if(dayTime.length != 0){
	    	
	    
	    for(var i=0;i<dayTime.length;i++){
	    	if(dNight[i]>90 ||  sNight[i]>140){
	    		$("#dateN"+i).html(dayTime[i])
	    		$("#dateN"+i).addClass("td-color-red");
	    	}else{
	    		$("#dateN"+i).html(dayTime[i])
	    	}
	    	if(dNight[i]>90){
	    		$("#nights"+i).html(dNight[i]);
	    		$("#nights"+i).addClass("td-color-red");
	    	/*	nightdbp+='<td class="td-color-red">'+dNight[i]+'</td>'*/
	    	}else{
	    		$("#nights"+i).html(dNight[i]);
	    	/*	nightdbp+='<td >'+dNight[i]+'</td>'*/
	    	}
	    	if( sNight[i]>140){
	    		$("#nightd"+i).html(sNight[i]);
	    		$("#nightd"+i).addClass("td-color-red");
	    		/*nightsbp+='<td class="td-color-red">'+sNight[i]+'</td>'*/
	    	}else{
	    		$("#nightd"+i).html(sNight[i]);
	    		/*nightsbp+='<td >'+sNight[i]+'</td>'*/
	    	}
	    	(dNight[i]+sNight[i])>=(dNight[indexNight]+sNight[indexNight]) ?(indexNight=i):(indexNight=indexNight)
	    	
	    }
	    $("#nightMax").html("最高一次测量值为"+sNight[indexNight]+"/"+dNight[indexNight]+"("+dayTime[indexNight]+")")
	   /* $("#date2").html(strnight)
	    $("#nights").html(nightsbp)
	    $("#nightd").html(nightdbp)*/
	    var dDay=[];
	    var sDay=[];
		  $("input[name='diastolicDayAvg1']").each(function(index,a){
			  dDay.push($(this).val())
			});
		
		  $("input[name='systolicDayAvg1']").each(function(index,a){
			  sDay.push($(this).val())		  
			});
		   	var strday='';
		    var daysbp='';
		    var daydbp='';
		    var indexDay=0;
		    for(var j=0;j<dayTime.length;j++){    	
		    	if(dDay[j]>90 || sDay[j]>140){	
		    		$("#date"+j).html(dayTime[j])
		    		$("#date"+j).addClass("td-color-red");
		    	}else{
		    		$("#date"+j).html(dayTime[j])
		    	}
		    	if(dDay[j]>90){
		    		 $("#dayd"+j).html(dDay[j])
		    		 $("#dayd"+j).addClass("td-color-red");
		    		
		    	}else{
		    		 $("#dayd"+j).html(dDay[j])
		    	}
		    	if( sDay[j]>140){
		    		$("#days"+j).html(sDay[j]);
		    		$("#days"+j).addClass("td-color-red");
		    		
		    	}else{
		    		$("#days"+j).html(sDay[j]);
		    	
		    	}
		    	
		    		(dDay[j]+sDay[j])>=(dDay[indexDay]+sDay[indexDay]) ?(indexDay=j) :(indexDay=indexDay)
		    	
		    	
		    }
		   $("#dayMax").html("最高一次测量值为"+sDay[indexDay]+"/"+dDay[indexDay]+"("+dayTime[indexDay]+")")
		  /*  $("#date1").html(strday)
		    $("#days").html(daysbp)
		    $("#dayd").html(daydbp)*/
			 var totalDiastolicDayAvg1=0;
			  $("input[name='diastolicDayAvg1']").each(function(index,a){
				  totalDiastolicDayAvg1 += parseInt($(this).val())
				  j=index
				});
			var diastolicDayAvg1=[totalDiastolicDayAvg1/$("input[name='diastolicDayAvg1']").length];
			 var totalSystolicDayAvg1=0;
			  $("input[name='systolicDayAvg1']").each(function(index,a){
				  totalSystolicDayAvg1 += parseInt($(this).val())
				  j=index
				});
			var systolicDayAvg1=[totalSystolicDayAvg1/$("input[name='systolicDayAvg1']").length];
			 var totalDiastolicNightAvg1=0;
			  $("input[name='diastolicNightAvg1']").each(function(index,a){
				  totalDiastolicNightAvg1 += parseInt($(this).val())
				});
			var diastolicNightAvg1=[totalDiastolicNightAvg1/$("input[name='diastolicNightAvg1']").length];
			 var totalSystolicNightAvg1=0;
			  $("input[name='systolicNightAvg1']").each(function(index,a){
				  totalSystolicNightAvg1 += parseInt($(this).val())
				});
			var systolicNightAvg1=[totalSystolicNightAvg1/$("input[name='systolicNightAvg1']").length];
		   $("#avg").html("最近一周的平均值为早晨"+parseInt(systolicDayAvg1) +"/"+parseInt(diastolicDayAvg1)+"，夜晚"+parseInt(systolicNightAvg1)+"/"+parseInt(diastolicNightAvg1))
	    }else{
	    	$("#dayMax").html("最高一次测量值无数据")
	    	$("#nightMax").html("最高一次测量值无数据")
	    	 $("#avg").html("无数据")
	    	 }
}

//最近一周白天平均值
function WeekDayCanvas(){
	var can1 = document.getElementById("canvas-day");  
    var ctx = can1.getContext("2d");
    
    //绘制中轴
    ctx.beginPath();
    ctx.moveTo(170,0);  
    ctx.lineTo(170,can1.height); 
    ctx.strokeStyle  = "#818181";
    ctx.closePath();  
    ctx.stroke();     

    //绘制基准线
    //90mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(40,110);  
    ctx.lineTo(300,110);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke();
    //140mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(40,60);  
    ctx.lineTo(300,60);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke(); 
    
    //绘制行
    var rows = 8;  
    //列步长  
    var rW = can1.height/rows;  
    for (var i = 0 ; i <= rows; i ++){  
        ctx.beginPath();  
        //绘制行  
        ctx.setLineDash([2,2]);//虚线效果
        ctx.moveTo(40,i*rW);  
        ctx.lineTo(can1.width,i*rW);  
        //绘制坐标点  
        ctx.font = "14px scans-serif";  
        ctx.fillStyle = "#818181"; 
        ctx.strokeStyle  = "#c1c1c1"; 
        var colsNo = ctx.measureText(i*20+40);//设置好字体才能计算字体宽度  
        ctx.fillText(i*20+40,30-colsNo.width,can1.height - i*20);  
        //绘制图标左侧边线,为了避免重新定义绘制它的方法，这里把它放在for循环里面，所以在相同位置画了10遍  
        ctx.moveTo(40,0);  
        ctx.lineTo(40,can1.height);  
        ctx.closePath();  
        ctx.stroke();  
    }

    //绘制X轴
    ctx.beginPath();
    ctx.moveTo(40,159);  
    ctx.lineTo(300,159); 
    ctx.strokeStyle  = "#818181";
    ctx.closePath();  
    ctx.stroke();
    
    //绘制柱状图
    
    var totalDiastolicDayAvg=0;
	  $("input[name='diastolicDayAvg']").each(function(index,a){
		  totalDiastolicDayAvg += parseInt($(this).val())
		  j=index
		});
	var diastolicDayAvg=[totalDiastolicDayAvg/$("input[name='diastolicDayAvg']").length];
	 var totalSystolicDayAvg=0;
	  $("input[name='systolicDayAvg']").each(function(index,a){
		  totalSystolicDayAvg += parseInt($(this).val())
		  j=index
		});
	var systolicDayAvg=[totalSystolicDayAvg/$("input[name='systolicDayAvg']").length];
	 var totalDiastolicDayAvg1=0;
	  $("input[name='diastolicDayAvg1']").each(function(index,a){
		  totalDiastolicDayAvg1 += parseInt($(this).val())
		  j=index
		});
	var diastolicDayAvg1=[totalDiastolicDayAvg1/$("input[name='diastolicDayAvg1']").length];
	 var totalSystolicDayAvg1=0;
	  $("input[name='systolicDayAvg1']").each(function(index,a){
		  totalSystolicDayAvg1 += parseInt($(this).val())
		  j=index
		});
	var systolicDayAvg1=[totalSystolicDayAvg1/$("input[name='systolicDayAvg1']").length];
    var a=[parseInt(systolicDayAvg) ,parseInt(diastolicDayAvg)]
    var b=[parseInt(systolicDayAvg1),parseInt(diastolicDayAvg1)]
    var dataArr = [a,b];//虚拟数据
    var colors = [['#fc8215','#818181'],['#ffc30e','#020202']]
    for (var i = 0 ; i < dataArr.length; i ++){ 
    	ctx.strokeStyle = colors[i][0];  
        ctx.fillStyle = colors[i][0];
        ctx.beginPath();
        ctx.setLineDash([]);
        ctx.rect(65*(2*i+1)+25,can1.height+40-dataArr[i][0],30,dataArr[i][0]-dataArr[i][1]);  
        ctx.fill();
        //绘制柱状图顶部数值  
        ctx.font = "18px scans-serif";  
        ctx.fillStyle = colors[i][1];  
        ctx.fillText(dataArr[i][0],65*(2*i+1)+25,can1.height+35-dataArr[i][0]);
        ctx.fillText(dataArr[i][1],65*(2*i+1)+25,can1.height+60-dataArr[i][1]);
        ctx.closePath();  
        ctx.stroke();
    }

}

//最近一周夜晚平均值
function WeekNightCanvas(){
	var can2 = document.getElementById("canvas-night");  
    var ctx = can2.getContext("2d");
    
    //绘制中轴
    ctx.beginPath();
    ctx.moveTo(170,0);  
    ctx.lineTo(170,can2.height); 
    ctx.strokeStyle  = "#818181";
    ctx.closePath();  
    ctx.stroke(); 
    
    //绘制基准线
    //90mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(40,110);  
    ctx.lineTo(300,110);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke();
    //140mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(40,60);  
    ctx.lineTo(300,60);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke(); 
    
    //绘制行
    var rows = 8;  
    //列步长  
    var rW = can2.height/rows;  
    for (var i = 0 ; i <= rows; i ++){  
        ctx.beginPath();  
        //绘制行  
        ctx.setLineDash([2,2]);//虚线效果
        ctx.moveTo(40,i*rW);  
        ctx.lineTo(can2.width,i*rW);  
        //绘制坐标点  
        ctx.font = "14px scans-serif";  
        ctx.fillStyle = "#818181"; 
        ctx.strokeStyle  = "#c1c1c1"; 
        var colsNo = ctx.measureText(i*20+40);//设置好字体才能计算字体宽度  
        ctx.fillText(i*20+40,30-colsNo.width,can2.height - i*20);  
        //绘制图标左侧边线,为了避免重新定义绘制它的方法，这里把它放在for循环里面，所以在相同位置画了10遍  
        ctx.moveTo(40,0);  
        ctx.lineTo(40,can2.height);  
        ctx.closePath();  
        ctx.stroke();  
    }

    //绘制X轴
    ctx.beginPath();
    ctx.moveTo(40,159);  
    ctx.lineTo(300,159); 
    ctx.strokeStyle  = "#818181";
    ctx.closePath();  
    ctx.stroke();
    
    //绘制柱状图
    var totalDiastolicNightAvg=0;
	  $("input[name='diastolicNightAvg']").each(function(index,a){
		  totalDiastolicNightAvg += parseInt($(this).val())
		});
	var diastolicNightAvg=[totalDiastolicNightAvg/$("input[name='diastolicNightAvg']").length];
	 var totalSystolicNightAvg=0;
	  $("input[name='systolicNightAvg']").each(function(index,a){
		  totalSystolicNightAvg += parseInt($(this).val())
		});
	var systolicNightAvg=[totalSystolicNightAvg/$("input[name='systolicNightAvg']").length];
	 var totalDiastolicNightAvg1=0;
	  $("input[name='diastolicNightAvg1']").each(function(index,a){
		  totalDiastolicNightAvg1 += parseInt($(this).val())
		});
	var diastolicNightAvg1=[totalDiastolicNightAvg1/$("input[name='diastolicNightAvg1']").length];
	 var totalSystolicNightAvg1=0;
	  $("input[name='systolicNightAvg1']").each(function(index,a){
		  totalSystolicNightAvg1 += parseInt($(this).val())
		});
	var systolicNightAvg1=[totalSystolicNightAvg1/$("input[name='systolicNightAvg1']").length];
  var a=[parseInt(systolicNightAvg) ,parseInt(diastolicNightAvg) ]
  var b=[parseInt(systolicNightAvg1) ,parseInt(diastolicNightAvg1)]
    var dataArr = [a,b];//虚拟数据
    var colors = [['#00a99d','#818181'],['#0a686a','#020202']]
    for (var i = 0 ; i < dataArr.length; i ++){ 
    	ctx.strokeStyle = colors[i][0];  
        ctx.fillStyle = colors[i][0];
        ctx.beginPath();
        ctx.setLineDash([]);
        ctx.rect(65*(2*i+1)+25,can2.height+40-dataArr[i][0],30,dataArr[i][0]-dataArr[i][1]);  
        ctx.fill();
        //绘制柱状图顶部数值  
        ctx.font = "18px scans-serif";  
        ctx.fillStyle = colors[i][1];  
        ctx.fillText(dataArr[i][0],65*(2*i+1)+25,can2.height+35-dataArr[i][0]);
        ctx.fillText(dataArr[i][1],65*(2*i+1)+25,can2.height+60-dataArr[i][1]);
        ctx.closePath();  
        ctx.stroke();
    }

}
//最近一周每天平均值
function WeekEveryDayCanvas(){
	
	var can3 = document.getElementById("canvas-everyday");  
    var ctx = can3.getContext("2d");
    
    //绘制行
    var rows = 14;  
    //列步长  
    var rW = (can3.height-30)/rows;
    for (var i = 0 ; i <= rows; i ++){  
        ctx.beginPath();  
        //绘制行  
        ctx.setLineDash([2,3]);//虚线效果
        ctx.moveTo(40,i*rW);  
        ctx.lineTo(can3.width,i*rW);  
        //绘制坐标点  
        ctx.font = "14px scans-serif";  
        ctx.fillStyle = "#818181"; 
        ctx.strokeStyle  = "#c1c1c1"; 
        var colsNo = ctx.measureText(i*10+50);//设置好字体才能计算字体宽度  
        ctx.fillText(i*10+50,35-colsNo.width,can3.height-30 - i*25);          
        ctx.closePath();  
        ctx.stroke();  
    }
    
    //绘制X轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(40,350);  
    ctx.lineTo(330,350); 
    ctx.closePath();  
    ctx.stroke(); 
    
    //绘制Y轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(40,0);  
    ctx.lineTo(40,can3.height-30);   
    ctx.closePath();  
    ctx.stroke();
    
    //绘制右侧Y轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(329,0);  
    ctx.lineTo(329,can3.height-30);   
    ctx.closePath();  
    ctx.stroke();

    //绘制基准线
    //90mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(40,250);  
    ctx.lineTo(330,250);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke();
    //140mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(40,125);  
    ctx.lineTo(330,125);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke(); 
    
    //绘制折线图
    var dayTime=[];
    $("input[name='dayTime1']").each(function(index,a){
    	dayTime.push(timestampToTime($(this).val()))
		});
    var night=[];
    var dNight=[];
    var sNight=[];
	  $("input[name='diastolicNightAvg1']").each(function(index,a){
		  dNight.push($(this).val())
		});
	
	  $("input[name='systolicNightAvg1']").each(function(index,a){
		  sNight.push($(this).val())		  
		});
	  for(var i=0;i<dNight.length;i++){
		  night.push([dNight[i],sNight[i]])
	  }	
	  var day=[];
	  var dDay=[];
	  var sDay=[]; 
	  $("input[name='diastolicDayAvg1']").each(function(index,a){
		  dDay.push($(this).val())
		});
	  $("input[name='systolicDayAvg1']").each(function(index,a){
		  sDay.push($(this).val())
		});
	  for(var j=0;j<dDay.length;j++){
		  day.push([dDay[j],sDay[j]])
	  }	
	  
	  /*var datadayArr = [[128,70],[128,78],[133,84],[130,74],[138,72],[115,76],[137,90]];//白天虚拟数据
    var datanightArr = [[132,68],[130,90],[128,84],[126,65],[131,67],[123,85],[130,71]];//夜晚虚拟数据*/
      var datanightArr=night;
      var datadayArr=day;
   /*var datatime = ["日","一","二","三","四","五","六"];*/
      var datatime = dayTime
    var colors = ['#fd7445','#0a686a'];
    var Xwidth = can3.width - 40;
    
	//绘制白天折线
    for (var i = 0 ; i < datadayArr.length; i ++){
        ctx.setLineDash([]);
        if(i<datadayArr.length -1){ 
        	//白天高压终止坐标  
        	var HdaysNY = 350-(datadayArr[i+1][0]-50)/10*25;  
            var HdaysNX = Xwidth/7*(i+1) + Xwidth/14 + 40;
        	//白天低压终止Y坐标  
            var LdaysNY = 350-(datadayArr[i+1][1]-50)/10*25;
        	//夜晚高压终止Y坐标  
            var HnightsNY = 350-(datanightArr[i+1][0]-50)/10*25;
        	//夜晚低压终止Y坐标  
            var LnightsNY = 350-(datanightArr[i+1][1]-50)/10*25;
        }
    	//白天高压起始坐标  
        var HdaysY = 350-(datadayArr[i][0]-50)/10*25;  
        var HdaysX = Xwidth/7*i + Xwidth/14 + 40;
    	//白天低压起始Y坐标  
        var LdaysY = 350-(datadayArr[i][1]-50)/10*25; 
        //夜晚高压起始Y坐标  
        var HnightsY = 350-(datanightArr[i][0]-50)/10*25;
    	//夜晚低压起始Y坐标  
        var LnightsY = 350-(datanightArr[i][1]-50)/10*25; 
 
        //白天高压折线
        ctx.beginPath();
        ctx.moveTo(HdaysX,HdaysY);  
        ctx.lineTo(HdaysNX,HdaysNY);  
        ctx.lineWidth = 1;  
        ctx.strokeStyle = colors[0];  
        ctx.closePath();  
        ctx.stroke();
        //白天低压折线
        ctx.beginPath();
        ctx.moveTo(HdaysX,LdaysY);  
        ctx.lineTo(HdaysNX,LdaysNY);  
        ctx.lineWidth = 1;  
        ctx.strokeStyle = colors[0];  
        ctx.closePath();  
        ctx.stroke();
        
        //夜晚高压折线
        ctx.beginPath();
        ctx.moveTo(HdaysX,HnightsY);  
        ctx.lineTo(HdaysNX,HnightsNY);  
        ctx.lineWidth = 1;  
        ctx.strokeStyle = colors[1];  
        ctx.closePath();  
        ctx.stroke();
        //夜晚低压折线
        ctx.beginPath();
        ctx.moveTo(HdaysX,LnightsY);  
        ctx.lineTo(HdaysNX,LnightsNY);  
        ctx.lineWidth = 1;  
        ctx.strokeStyle = colors[1];  
        ctx.closePath();  
        ctx.stroke();

        //绘制白天高压折线点
    	ctx.beginPath();
    	ctx.arc(HdaysX,HdaysY,2,0,360,false);
        ctx.strokeStyle = colors[0];
    	ctx.fillStyle = colors[0];//填充颜色,默认是黑色
    	ctx.fill();//画实心圆
        ctx.closePath();  
        ctx.stroke();
        //绘制白天低压折线点
    	ctx.beginPath();
    	ctx.arc(HdaysX,LdaysY,2,0,360,false);
        ctx.strokeStyle = colors[0];
    	ctx.fillStyle = colors[0];//填充颜色,默认是黑色
    	ctx.fill();//画实心圆
        ctx.closePath();  
        ctx.stroke();

        //绘制夜晚高压折线点
    	ctx.beginPath();
    	ctx.arc(HdaysX,HnightsY,2,0,360,false);
        ctx.strokeStyle = colors[1];
    	ctx.fillStyle = colors[1];//填充颜色,默认是黑色
    	ctx.fill();//画实心圆
        ctx.closePath();  
        ctx.stroke();
        //绘制夜晚低压折线点
    	ctx.beginPath();
    	ctx.arc(HdaysX,LnightsY,2,0,360,false);
        ctx.strokeStyle = colors[1];
    	ctx.fillStyle = colors[1];//填充颜色,默认是黑色
    	ctx.fill();//画实心圆
        ctx.closePath();  
        ctx.stroke();

        //绘制横坐标文字
        ctx.beginPath();
        var txtW = ctx.measureText(datatime[i]);
        ctx.fillStyle = "#818181";
        ctx.fillText(datatime[i],HdaysX-txtW.width/2,370);
        ctx.closePath();  
        ctx.stroke();
    } 
}
//24小时血压折线图
function DayHourCanvas(){
	var can4 = document.getElementById("canvas-dayhour");  
    var ctx = can4.getContext("2d");
    ctx.clearRect(0,0,1198,390);

    //绘制行
    var rows = 9;  
    //列步长  
    var rW = (can4.height-30)/rows;
    for (var i = 0 ; i <= rows; i ++){  
        ctx.beginPath();  
        //绘制行  
        ctx.setLineDash([2,3]);//虚线效果
        ctx.moveTo(0,i*rW);  
        ctx.lineTo(can4.width,i*rW);  
        //绘制坐标点  
        ctx.font = "14px scans-serif";  
        ctx.fillStyle = "#818181"; 
        ctx.strokeStyle  = "#c1c1c1"; 
        var colsNo = ctx.measureText(i*20+40);//设置好字体才能计算字体宽度  
        ctx.fillText(i*20+40,40-colsNo.width,can4.height-30 - i*40);
        ctx.fillText(i*20+40,1159,can4.height-30 - i*40);
        ctx.closePath();  
        ctx.stroke();  
    }
    
    //绘制X轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(0,360);  
    ctx.lineTo(1198,360); 
    ctx.closePath();  
    ctx.stroke(); 
    var datatime = [];
    for(var i = 0 ; i < datatime.length; i ++){
        //横坐标文字
    	ctx.beginPath();
    	ctx.font = "14px scans-serif";  
        ctx.fillStyle = "#818181"; 
        var text = ctx.measureText(datatime[i]);//设置好字体才能计算字体宽度  
    	ctx.fillText(datatime[i],59+45*i-text.width/2,can4.height-10);
        ctx.closePath();  
        ctx.stroke();
    	//横坐标标线
    	ctx.beginPath();
        ctx.moveTo(59+45*i,360);  
        ctx.lineTo(59+45*i,353);  
        ctx.lineWidth = 1;   
        ctx.setLineDash([]);
        ctx.strokeStyle = "#818181";
        ctx.closePath();  
        ctx.stroke();
    }
    
    //绘制Y轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(59,0);  
    ctx.lineTo(59,can4.height-30);   
    ctx.closePath();  
    ctx.stroke();
    
    //绘制右侧Y轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(1139,0);  
    ctx.lineTo(1139,can4.height-30);   
    ctx.closePath();  
    ctx.stroke();

    //绘制基准线
    //90mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(0,260);  
    ctx.lineTo(1198,260);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke();
    //140mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(0,160);  
    ctx.lineTo(1198,160);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke();
    
    //绘制折线图
    var dataHourArr = [];//白天虚拟数据
    var colors = ['#fd7445','#0a686a'];
    for (var i = 0 ; i < dataHourArr.length; i ++){
    	ctx.setLineDash([]);
    	if(i<24){
        	//绘制高压结束坐标
        	var HightNY = 360-(dataHourArr[i+1][0]-40)/20*40;
        	var HightNX = 59+45*(i+1);
        	//绘制低压结束坐标
        	var LowNY = 360-(dataHourArr[i+1][1]-40)/20*40;
    	}
    	//绘制高压起始坐标
    	var HightY = 360-(dataHourArr[i][0]-40)/20*40;
    	var HightX = 59+45*i;
    	//绘制低压起始坐标
    	var LowY = 360-(dataHourArr[i][1]-40)/20*40;
    	//绘制高压折线
    	ctx.beginPath();
        ctx.moveTo(HightX,HightY);  
        ctx.lineTo(HightNX,HightNY);  
        ctx.lineWidth = 1;  
        ctx.strokeStyle = colors[0];  
        ctx.closePath();  
        ctx.stroke();
        //绘制高压折线点
        ctx.beginPath();
    	ctx.arc(HightX,HightY,2,0,360,false);
        ctx.strokeStyle = colors[0];
    	ctx.fillStyle = colors[0];//填充颜色,默认是黑色
    	ctx.fill();//画实心圆
        ctx.closePath();  
        ctx.stroke();
        //绘制低压折线
    	ctx.beginPath();
        ctx.moveTo(HightX,LowY);  
        ctx.lineTo(HightNX,LowNY);  
        ctx.lineWidth = 1;  
        ctx.strokeStyle = colors[1];  
        ctx.closePath();  
        ctx.stroke();
        //绘制低压折线点
        ctx.beginPath();
    	ctx.arc(HightX,LowY,2,0,360,false);
        ctx.strokeStyle = colors[1];
    	ctx.fillStyle = colors[1];//填充颜色,默认是黑色
    	ctx.fill();//画实心圆
        ctx.closePath();  
        ctx.stroke();
    }
    
}

function GetAge() {
	var identityCard =$("#rAge").html();
    var len = (identityCard + "").length;
    if (len == 0) {
        return 0;
    } else {
        if ((len != 15) && (len != 18))//身份证号码只能为15位或18位其它不合法
        {
            return 0;
        }
    }
    var strBirthday = "";
    if (len == 18)//处理18位的身份证号码从号码中得到生日和性别代码
    {
        strBirthday = identityCard.substr(6, 4) + "/" + identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
    }
    if (len == 15) {
        strBirthday = "19" + identityCard.substr(6, 2) + "/" + identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
    }
    //时间字符串里，必须是“/”
    var birthDate = new Date(strBirthday);
    var nowDateTime = new Date();
    var age = nowDateTime.getFullYear() - birthDate.getFullYear();
    //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
    if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
        age--;
    }
    $("#rAge").html(age);
}
function timestampToTime(timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/';
    D = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() + ':';
    s = date.getSeconds();
    return M+D;
}
function timestampToHour(timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/';
    D = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() ;
    s = date.getSeconds();
    return h+m;
}
//24小时血压折线图
function DayHourCanvasByDay(date,xueya,result){
	var can4 = document.getElementById("canvas-dayhour");  
    var ctx = can4.getContext("2d");
    ctx.clearRect(0,0,1198,390);
    //绘制行
    var rows = 9;  
    //列步长  
    var rW = (can4.height-30)/rows;
    for (var i = 0 ; i <= rows; i ++){  
        ctx.beginPath();  
        //绘制行  
        ctx.setLineDash([2,3]);//虚线效果
        ctx.moveTo(0,i*rW);  
        ctx.lineTo(can4.width,i*rW);  
        //绘制坐标点  
        ctx.font = "14px scans-serif";  
        ctx.fillStyle = "#818181"; 
        ctx.strokeStyle  = "#c1c1c1"; 
        var colsNo = ctx.measureText(i*20+40);//设置好字体才能计算字体宽度  
        ctx.fillText(i*20+40,40-colsNo.width,can4.height-30 - i*40);
        ctx.fillText(i*20+40,1159,can4.height-30 - i*40);
        ctx.closePath();  
        ctx.stroke();  
    }
    
    //绘制X轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(0,360);  
    ctx.lineTo(1198,360); 
    ctx.closePath();  
    ctx.stroke(); 
    var datatime = ["00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00"
                    ,"09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00"
                    ,"18:00","19:00","20:00","21:00","22:00","23:00","00:00"];
//    var datatime=date;
    for(var i = 0 ; i < datatime.length; i ++){
        //横坐标文字
    	ctx.beginPath();
    	ctx.font = "14px scans-serif";  
        ctx.fillStyle = "#818181"; 
        var text = ctx.measureText(datatime[i]);//设置好字体才能计算字体宽度  
    	ctx.fillText(datatime[i],59+45*i-text.width/2,can4.height-10);
        ctx.closePath();  
        ctx.stroke();
    	//横坐标标线
    	ctx.beginPath();
        ctx.moveTo(59+45*i,360);  
        ctx.lineTo(59+45*i,353);  
        ctx.lineWidth = 1;   
        ctx.setLineDash([]);
        ctx.strokeStyle = "#818181";
        ctx.closePath();  
        ctx.stroke();
    }
    
    //绘制Y轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(59,0);  
    ctx.lineTo(59,can4.height-30);   
    ctx.closePath();  
    ctx.stroke();
    
    //绘制右侧Y轴
    ctx.beginPath();
    ctx.setLineDash([]);
    ctx.strokeStyle  = "#818181";
    ctx.moveTo(1139,0);  
    ctx.lineTo(1139,can4.height-30);   
    ctx.closePath();  
    ctx.stroke();

    //绘制基准线
    //90mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(0,260);  
    ctx.lineTo(1198,260);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke();
    //140mmHg
    ctx.beginPath();
    ctx.setLineDash([3,3]);//虚线效果
    ctx.moveTo(0,160);  
    ctx.lineTo(1198,160);
    ctx.strokeStyle  = "#ff0000";
    ctx.closePath();  
    ctx.stroke();
    
    //绘制折线图
  /*  var dataHourArr = [[128,70],[128,78],[133,84],[130,74],[138,72],[115,76],[137,90],[128,78],[133,84],[130,74],[138,72],[115,76],[137,90],[128,78],[133,84],[130,74],[138,72],[115,76],[137,90],[128,78],[133,84],[130,74],[138,72],[115,76],[137,90]];//白天虚拟数据
*/    
    var dataHourArr=xueya;
    var dataHourtime=date;
    var dataHourtimebase = result;
    var colors = ['#fd7445','#0a686a'];
    for (var i = 0 ; i < dataHourArr.length; i ++){
    	ctx.setLineDash([]);
    	if(i<dataHourArr.length-1){
        	//绘制高压结束坐标
        	var HightNY = 360-(dataHourArr[i+1][0]-40)/20*40;
        	var HightNX = 59+45*(new Date(dataHourtimebase[i+1].time).getHours() + new Date(dataHourtimebase[i+1].time).getMinutes()/60);
        	//绘制低压结束坐标
        	var LowNY = 360-(dataHourArr[i+1][1]-40)/20*40;
    	}
    	//绘制高压起始坐标
    	var HightY = 360-(dataHourArr[i][0]-40)/20*40;
    	var HightX = 59+45*(new Date(dataHourtimebase[i].time).getHours() + new Date(dataHourtimebase[i].time).getMinutes()/60);
    	//绘制低压起始坐标
    	var LowY = 360-(dataHourArr[i][1]-40)/20*40;
    	//绘制高压折线
    	ctx.beginPath();
        ctx.moveTo(HightX,HightY);  
        ctx.lineTo(HightNX,HightNY);  
        ctx.lineWidth = 1;  
        ctx.strokeStyle = colors[0];  
        ctx.closePath();  
        ctx.stroke();
        //绘制高压折线点
        ctx.beginPath();
    	ctx.arc(HightX,HightY,2,0,360,false);
        ctx.strokeStyle = colors[0];
    	ctx.fillStyle = colors[0];//填充颜色,默认是黑色
    	ctx.fill();//画实心圆
        ctx.closePath();  
        ctx.stroke();
        //绘制低压折线
    	ctx.beginPath();
        ctx.moveTo(HightX,LowY);  
        ctx.lineTo(HightNX,LowNY);  
        ctx.lineWidth = 1;  
        ctx.strokeStyle = colors[1];  
        ctx.closePath();  
        ctx.stroke();
        //绘制低压折线点
        ctx.beginPath();
    	ctx.arc(HightX,LowY,2,0,360,false);
        ctx.strokeStyle = colors[1];
    	ctx.fillStyle = colors[1];//填充颜色,默认是黑色
    	ctx.fill();//画实心圆
        ctx.closePath();  
        ctx.stroke();
    }
    
}